import 'dart:convert';

T? asT<T>(dynamic value) {
  if (value is T) {
    return value;
  }
  return null;
}

class PayRuleModel {
  PayRuleModel({
    this.unitPrice,
    this.billingMode,
    this.price,
    this.id,
    this.day,
    this.isHot,
    this.giftDays,
  });

  factory PayRuleModel.fromJson(Map<String, dynamic> jsonRes) => PayRuleModel(
        unitPrice: asT<double>(jsonRes['unitPrice']),
        billingMode: asT<int>(jsonRes['billingMode']),
        price: asT<String>(jsonRes['price']),
        id: asT<int>(jsonRes['id']),
        day: asT<String>(jsonRes['day']),
        isHot: asT<bool>(jsonRes['isHot']),
        giftDays: asT<String>(jsonRes['giftDays']),
      );

  double? unitPrice;
  int? billingMode;
  String? price;
  int? id;
  String? day;
  bool? isHot;
  String? giftDays;

  @override
  String toString() {
    return jsonEncode(this);
  }

  Map<String, dynamic> toJson() => <String, dynamic>{
        'unitPrice': unitPrice,
        'billingMode': billingMode,
        'price': price,
        'id': id,
        'day': day,
        'isHot': isHot,
        'giftDays': giftDays,
      };
}
